package org.jground.rx.ui.zk.viewControl;

import org.jground.rx.RXType;
import org.jground.rx.RXView;
import org.jground.rx.ui.IUIAttributeView;
import org.jground.rx.ui.zk.UIFrame;
import org.jground.util.ArrayUtils;
import org.jground.zk.zulX.HboxX;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Label;

public class UIAttributeViewBoolean extends UIAttributeViewBase {

    private HboxX stringDIV;
    private boolean isPercentage;
    private Label label;

    private UIAttributeViewBoolean(UIFrame uiFrame, RXView moView) {
        super(uiFrame, moView);
        add(stringDIV = new HboxX());
        isPercentage = RXType.PERCENTAGE.equals(moView.getRXAttribute().getRXType().getBaseType().getTypeId());
        label = new Label();
        add(label);
    }

    public UIAttributeViewBoolean() {}

    public void set(String... values) {
        clear();
        if (ArrayUtils.isNotEmpty(values)) {
            String v = values[0] + (isPercentage ? "%" : "");
            label.setValue(v);
            renderToStringS.add(v);
        }
    }

    public void clear() {
        stringDIV.removeAll();
        renderToStringS.clear();
    }

    public IUIAttributeView<Component,UIFrame> createNew(UIFrame uiFrame, RXView moControl) {
        return new UIAttributeViewBoolean(uiFrame, moControl);
    }
}